import urllib.request
from urllib.error import HTTPError,URLError
# print(HTTPError.mro())

# urllib.request 提示错误 HTTPError UrlError
'''
urllib.error.URLError: <urlopen error [Errno 11001] getaddrinfo failed>   :url
urllib.error.HTTPError: HTTP Error 404: Not Found                         :http
'''

url = "http://www.vbsdvbsdv.cn"  #URLError
# url = "https://www.cnblogs.com/volcao/p/110"  #HTTPError

try:
    response = urllib.request.urlopen(url)
except HTTPError as error:
    print(error.code)

    #可以用来判断
    if error.code == 404:
        pass


except URLError as error:
    print(error)


#HTTPError的父类是URLError
#继承关系
'''
[<class 'urllib.error.HTTPError'>, <class 'urllib.error.URLError'>, <class 'OSError'>, <class 'Exception'>, <class 'BaseException'>, <class 'urllib.response.addinfourl'>,
 <class 'urllib.response.addinfo'>, <class 'urllib.response.addbase'>, <class 'tempfile._TemporaryFileWrapper'>, <class 'object'>]
'''